class AverageUtils {
    private maxNum: number;
    private nums: Array<number> = [];
    private numsLen: number = 0;
    private numSum: number = 0;

    public constructor(maxNum: number = 10) {
        this.maxNum = maxNum;
    }

    public push(value: number): void {
        if (this.numsLen > this.maxNum) {
            this.numsLen--;
            this.numSum -= this.nums.shift();
        }
        this.nums.push(value);
        this.numSum += value;
        this.numsLen++;
    }

    //获取平均数
    public getValue(): number {
        return this.numSum / this.numsLen;
    }

    public clear(): void {
        this.nums.splice(0);
        this.numsLen = 0;
        this.numSum = 0;
    }
}